package com.example.common.core.domain;

import com.example.common.constant.HttpStatus;
import lombok.Data;

/**
 * 返回类型工具类（包装）
 * */
@Data
// @ApiModel("返回值 实体类")
public class Result<T> {

    /**
     * 响应码
     */
    private Integer code;
    /**
     * 响应消息
     */
    private String msg;
    /**
     * 返回数据
     */
    private T data;


    public Result() {}

    public Result(Integer code, String msg){
        this.code = code;
        this.msg = msg;
    }


    public Result(Integer code, String msg, T data){
        this.code = code;
        this.msg = msg;
        if (data != null){
            this.data = data;
        }
    }


    public static <T> Result<T> success(){
        return new Result<>(HttpStatus.SUCCESS,"成功");
    }

    public static <T> Result<T> success(String msg){
        return new Result<>(HttpStatus.SUCCESS,msg);
    }

    public static <T> Result<T> success(T data){
        return new Result<>(HttpStatus.SUCCESS,"成功",data);
    }

    public static <T> Result<T> success(T data,String msg){
        return new Result<>(HttpStatus.SUCCESS,msg,data);
    }

    public static <T> Result<T> warn(String msg)
    {
        return new Result<>(HttpStatus.WARN,msg);
    }

    public static <T> Result<T> warn(String msg, T data)
    {
        return new Result<>(HttpStatus.WARN,msg,data);
    }

    public static <T> Result<T> error(){
        return new Result<>(HttpStatus.ERROR,"失败");
    }

    public static <T> Result<T> error(String msg){
        return new Result<>(HttpStatus.ERROR,msg);
    }

    public static <T> Result<T> error(Integer code,String msg){
        return new Result<>(code,msg);
    }
    
    public static <T> Result<T> error(String msg,T data){
        return new Result<>(HttpStatus.ERROR,msg,data);
    }


}
